package com.weddingee.action.home;

import com.weddingee.action.base.BaseAction;
import com.weddingee.model.PhotoGroup;
import com.weddingee.dao.base.BaseDao;
import com.weddingee.dao.home.PhotoGroupDao;
import com.weddingee.dto.ViewDto;
import com.weddingee.util.DaoFactory;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import com.weddingee.model.News;
import java.util.Date;

public class PhotoGroupAction extends BaseAction{
	
	private PhotoGroupDao photoGroupDao = (PhotoGroupDao)DaoFactory.create(5);
	private Long id;
	private Long userId;
	private String name;
	private String url;
	private List<PhotoGroup> photoGroupList;
	private ViewDto view = new ViewDto();
	
	public ViewDto getView() {
		return view;
	}

	public void setView(ViewDto view) {
		this.view = view;
	}

	//add
	public String add(){
		//userId=5L;
		PhotoGroup photoGroup = new PhotoGroup();
		photoGroup.setUserId(userId);
		photoGroup.setName(name);
		photoGroup.setUrl(url);
		photoGroupDao.save(photoGroup);
		return SUCCESS;
	}
	
	//list
	  public String list(){
		
	     photoGroupList = photoGroupDao.listPhotoGroup(userId); 
	     System.out.println(photoGroupList);
		 return SUCCESS;
	  }
	  
	  //update
	  public String update(){
		 // id=8L;
		  //name="sadsadsadsadsad";
		  //url="asdsdsdsdsdsdsdsd.jsp";
		  PhotoGroup photoGroup = photoGroupDao.find(id);
		  if(name != null)
		  {photoGroup.setName(name);
		  }
		  if(url != null){
			 photoGroup.setUrl(url);
		  }
		
		  photoGroupDao.update(photoGroup);
		  return SUCCESS;
	  }
	   
	 
	  //delete
	  public String delete(){
		 // id=3L;
		  photoGroupDao.delete(id);
		  return SUCCESS;
	  }
	  
	  public String find() {
			try {
				PhotoGroup photoGroup = photoGroupDao.find(id);
				view.setData(photoGroup);
				return SUCCESS;
			} catch (Exception e) {
				return ERROR;
			}
		}
	
	
	
	public PhotoGroupDao getPhotoGroupDao() {
		return photoGroupDao;
	}
	public void setPhotoGroupDao(PhotoGroupDao photoGroupDao) {
		this.photoGroupDao = photoGroupDao;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	
	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}

	public List<PhotoGroup> getPhotoGroupList() {
		return photoGroupList;
	}

	public void setPhotoGroupList(List<PhotoGroup> photoGroupList) {
		this.photoGroupList = photoGroupList;
	}
	
	
  

	
}
